<?php
error_reporting(0);
date_default_timezone_set("Asia/Shanghai");

ob_start();
session_start();
$tts = date("YmdHis",time());
$password = "ffep2019";
//其他
function get_config($file, $ini, $type="string"){ 
	if(!file_exists($file)) 
		return false; 
		$str = file_get_contents($file); 
	if ($type=="int"){ 
		$config = preg_match("/".preg_quote($ini)."=(.*);/", $str, $res); 
		return $res[1]; 
	}else{ 
		$config = preg_match("/".preg_quote($ini)."=\"(.*)\";/", $str, $res); 
		if(!isset($res[1])){ 
		$config = preg_match("/".preg_quote($ini)."='(.*)';/", $str, $res); 
		} 
		if(isset($res[1])){
			return $res[1]; 
		}else{
			return false; 
		}
	} 
} 
function updateconfig($file, $ini, $value,$type="string"){ 
	$str = file_get_contents($file); 
	$str2=""; 
	if($type=="int"){ 
		$str2 = preg_replace('/' . $ini . "=(.*);/", $ini . '=' . $value . ';', $str); 
	}else{ 
		$str2 = preg_replace('/' . $ini . "=(.*);/", $ini . '=\'' . $value . '\';',$str); 
	} 
	file_put_contents($file, $str2);
}

 ?>
 <!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>后台管理</title>
<meta name="author" content="andy - vip@d163.net">
<meta name="copyright" content="www.d163.net">
<link href="https://lib.baomitu.com/twitter-bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="http://at.alicdn.com/t/font_374778_ixtunt1c0v.css">
<link href="inc/css/wap.css?v=<?php echo $tts;?>" rel="stylesheet" type="text/css" />
<script src="inc/js/ajax_wap.js?v=<?php echo $tts;?>" type="text/javascript"></script>
<style>
	html{font-size: 16px;}
	header { background-color: #2196F3; color: #ffffff;position: relative; }
	header .back {position: absolute; left: 10px; top: 0px; }
	header .back .iconfont {color: #ffffff; font-size: 28px; }
	.hd-title {text-align: center; padding: 10px 0; }
	.toggle-nav {z-index: 1001; top: 0; right: 0; padding: 0px 10px; height: 44px; transition: .3s;}
	.toggle-nav:visited, .toggle-nav:hover{color: #ffffff;transform: rotateZ(180deg);}
	.main{padding-top: 14px;}
	.main .form-group label {font-weight: 700; color: #656565; }
	@media (min-width: 576px) { 
		html{font-size: 16px;}
	}

	@media (min-width: 768px){
		html{font-size: 18px;}
	}
	@media (min-width: 992px){
		html{font-size: 18.75px;}
	}
	@media (min-width: 1200px){ 
		/* //>=1200的设备  */
	}
</style>
</head>
<body>
<?php 

if(isset($_SESSION['pwd']) && $_SESSION['pwd'] == $password){

	if(isset($_POST['id'])&&$_POST['id']==1){
		//读取服务器端的session_id，如果没有的话赋值为-1
		$session_idd = empty($_SESSION['session_idd']) ? -1 : $_SESSION['session_idd'];

		//读取客户端的post_id,如果没有的话赋值为-2
		$post_id = empty($_POST['post_idd']) ? -2 : $_POST['post_idd'];

		//判断两个id是否相同，相同则说明已经处理过一次，不同则进行处理
		if($session_idd == $post_id){
			// echo "<h1>已经处理过了，不管了</h1>";

		} else{
			if($post_id != -2){
				$_SESSION['session_idd'] = $post_id;
				updateconfig("config.php", "title", $_POST['title']);
				updateconfig("config.php", "qd_title", $_POST['qd_title']);
				updateconfig("config.php", "qd_desc", $_POST['qd_desc']);
				updateconfig("config.php", "success_msg", $_POST['success_msg']);
				updateconfig("config.php", "failed_msg", $_POST['failed_msg']);
				 
				echo '<script language="javascript"> alert("修改成功，请到前台刷新查看效果。");window.location.href="admin.php?v='.$tts.'"</script>';

			}
		}
		
	}

}else{
	header("location:login.php?v={$tts}");
}

$file='config.php';
$type='string';
?>
<?php include 'menu.php'; ?>
<header>
	<div class="hd-title">基本设置</div>
	<a class="back" href="javascript:;" onclick="history.go(-1)"><i class="iconfont icon-left-circle"></i></a>
</header>
<div class="main">
<form method="post" action="admin.php?v=<?php echo $tts; ?>">
  <input type="hidden" name="id"  value="1">
  <input type="hidden" name="post_idd" value="<?php echo $tts; ?>">
  <div class="form-group">
    <label>网站标题设置：</label>
    <input type="text" name="title" class="form-control" placeholder="请输入网站标题" value="<?php echo get_config($file, 'title', $type) ?>">
  </div>
  <div class="form-group">
    <label>签到标题设置</label>
    <input type="text" name="qd_title" class="form-control" placeholder="请输入签到标题" value="<?php echo get_config($file, 'qd_title', $type) ?>">
  </div>
  <div class="form-group">
    <label>签到描述设置</label>
    <input type="text" name="qd_desc" class="form-control" placeholder="请输入签到描述" value="<?php echo get_config($file, 'qd_desc', $type) ?>">
  </div>
  <div class="form-group">
    <label>签到成功提醒</label>
    <input type="text" name="success_msg" class="form-control" placeholder="" value="<?php echo get_config($file, 'success_msg', $type) ?>">
  </div>
  <div class="form-group">
    <label>签到失败提醒</label>
    <input type="text" name="failed_msg" class="form-control" placeholder="" value="<?php echo get_config($file, 'failed_msg', $type) ?>">
  </div>
  <button type="submit" class="btn btn-primary btn-block">确定修改</button>
</form>
</div>
<script src="https://lib.baomitu.com/jquery/2.1.4/jquery.min.js"></script>
<script src="inc/js/mobile-menu.js?v=<?php echo $tts;?>"></script>
</body>
</html>